package javafx.com;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.BorderWidths;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class main extends Application {

	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage primaryStage) throws Exception {

		Button button = new Button();
		Button button2 = new Button("b2");
		button.setText("字体");
		
		button.setLayoutX(100);
		button.setLayoutY(100);
		button2.setLayoutX(300);
		button2.setLayoutY(300);
		
		button.setPrefWidth(200);
		button.setPrefHeight(200);
		button2.setPrefWidth(200);
		button2.setPrefHeight(200);
		// 设置字体
		button.setFont(Font.font("sans-serif",40));
		
		// 设置字体颜色
		button.setTextFill(Paint.valueOf("#8FCC6D"));
		
		// 设置背景色
		BackgroundFill backgroundFill = new BackgroundFill(Paint.valueOf("#8FBC8F"),new CornerRadii(20),new Insets(20));
		Background background = new Background(backgroundFill);
		button.setBackground(background);
		
		// 设置外边框
		BorderStroke borderStroke = new BorderStroke(Paint.valueOf("#8FCC6D"), BorderStrokeStyle.DASHED, new CornerRadii(20), new BorderWidths(5));
		Border border = new Border(borderStroke);
		button.setBorder(border);
		
		button2.setStyle(
				"-fx-background-color:#7CCD7C;"+
				"-fx-background-radius:20;"+
				"-fx-text-fill:#5CACEE;"
				);
		
		// 按钮点击事件
		button.setOnAction((event)->{
			// 此时返回的按钮就是button
			Button button3 = (Button)event.getSource();
			System.out.println("button的文本是= "+ button3.getText());
		});
		
		Group group = new Group();
		group.getChildren().add(button);
		group.getChildren().add(button2);
		
		Scene scene = new Scene(group);
		
		primaryStage.setScene(scene);
		
		primaryStage.setTitle("javafx");
		primaryStage.setWidth(600);
		primaryStage.setHeight(600);
		primaryStage.show();
		
		
	}

}
